define('framework/dropdown/GillionDropDownDirectiveConstructor',['angular'], function (angular) {
    return function ($parse,$timeout,$document,$compile,$tabindex,GillionLocationService,GillionMsgService) {
        var RadioDropdown,CheckBoxDropdown,DropdownFactory;
        var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
            hasProp = {}.hasOwnProperty;
        var DROPITEMOBJ = 'DROP_ITEM_OBJ';
        function BaseDropdown($scope, $attrs, $controller, $timeout, itemList) {
            this.$scope = $scope;
            this.$attrs = $attrs;
            this.$controller = $controller;
            this.$timeout = $timeout;
            this.itemList = !!itemList ? itemList : [];
            this.valueSeparator = $scope.valueSeparator || ',';
        };

        BaseDropdown.prototype.transObjToArr = function(obj){
            var result = [];
            for(var prop in obj){
                var item = {};
                item.key = prop;
                item.value = obj[prop];
                result.push(item);
            }
            return result;
        }

        BaseDropdown.prototype.apply = function(obj){
            var scope = this.$scope
            if(!scope.$root.$$phase){
                scope.$apply();
            }
        }

        BaseDropdown.prototype.addDefaultOption = function(){
            var initSource = [],
                scope = this.$scope;
            initSource.push(scope.defaultOption);
            if(scope.source){
                angular.forEach(scope.source,function(item){
                    //如果引用不变 子指令不会重新解析
                    initSource.push(angular.extend({},item));
                })
            }
            scope.$source = initSource;
            scope.sourceTemp = angular.copy(scope.$source);
            if(!scope.ngModelInit){
                scope.setModelValue(scope.valueGetter(scope.defaultOption));
                scope.display = scope.displayGetter(scope.defaultOption);
            }
        }
        /**
         * 初始化子选项列表
         */
        BaseDropdown.prototype.initItemList = function(){

            var scope = this.$scope,
                me = this,
                ulElement = scope.ulElement,
                liJqObj,dropItem;
            if(scope.timer2){
                $timeout.cancel(scope.timer2);
            }
            scope.timer2 = $timeout(function () {
                me.itemList = [];
                //设置样式（单选多选）
                angular.forEach( ulElement.find("li[ng-show!='addShow']"),function(litem){
                    liJqObj = angular.element(litem);
                    if(!liJqObj.hasClass("checkbox-all")){
                        dropItem = liJqObj.data(DROPITEMOBJ);
                        me.itemList.push(dropItem);
                    }
                });
                me.showSelect(scope.getModelValue());
            }, 100);
        }

        BaseDropdown.prototype.onBeforeSelect = function(item){
            var self = this;
            if (angular.isDefined(self.$attrs.onBeforeSelect)) {
                if (self.$scope.onBeforeSelect({
                        list: self,
                        item: item
                    }) === false) {
                    return false;
                }
            }
        }

        BaseDropdown.prototype.onSelect = function(item){
            var self = this;
            if (angular.isDefined(self.$attrs.onSelect)) {
                self.$scope.onSelect({
                    list: self,
                    item: item
                });
            }
        }

        BaseDropdown.prototype.selectItem = function(item) {
            var self = this;
            if (self.onBeforeSelect(item) === false) {
                return;
            }
            self.$scope.$selectedRow = item.itemObj;
            self.$scope.setModelValue(item.attrs.value);
            self.$scope.display=item.element.text();
            self.$scope.isShow=false;
            self.$scope.needFocus = true;
            self.$scope.inputText[0].focus();
            self.apply();

            self.onSelect(item);
        };
        //显示选择 用于显示
        BaseDropdown.prototype.showSelect = function(value) {
            var me = this,
                text = '';
            if(value!=undefined){
                var display = _.chain(me.itemList).filter(function(item){
                    return item.attrs.value == value;
                }).map(function(item){
                        me.$scope.$selectedRow = item.itemObj;
                        return item.element.text();
                }).value();
                //me.$scope.display = display.join(me.valueSeparator);
                text = display.join(me.valueSeparator);
                if(text || me.$scope.unmatchRemove){
                    me.$scope.display =text;
                }else{
                    if(!me.$scope.unmatchHide){
                        me.$scope.display =value;
                    }
                }
            }else{
                me.$scope.display = '';
            }
        };

        BaseDropdown.prototype.filterSource = function(text){
            var me = this,
                scope = me.$scope,
                sourceTemp,
                displayTemp;
            sourceTemp = _.chain(scope.sourceTemp).filter(
                function(item){
                    displayTemp = scope.displayGetter(item);
                    if(displayTemp && displayTemp.indexOf(text)!=-1){
                        return true;
                    }
                }).value();
            scope.$source = sourceTemp;
        };

        BaseDropdown.prototype.refreshSelect = function(newValue) {
            var me = this,
                scope = me.$scope,
                text = '';
            if(scope.filter){
                me.filterSource(newValue);
            }

            if(newValue!=undefined){
                var display = _.chain(me.itemList).filter(function(item){
                    return item.element.text() == newValue;
                }).map(function(item){
                    scope.$selectedRow = item.itemObj;
                    return item.attrs.value;
                }).value();
                text = display.join(me.valueSeparator);
                if(text || scope.unmatchRemove){
                    scope.setModelValue(text);
                }else{
                    if(me.$attrs.defaultOption && newValue == scope.displayGetter(scope.defaultOption)){
                        scope.setModelValue(scope.valueGetter(scope.defaultOption));
                    }else{
                        scope.setModelValue(newValue);
                    }

                }

            }else{
                scope.setModelValue('');
            }
        };

        BaseDropdown.prototype.displayInit =function(display,value){
            var myScope = this.scope,
                selectedRow = {};
            if(myScope.$selectedRow && myScope.$selectedRow!={} ){
                selectedRow = myScope.$selectedRow;
            }
            selectedRow[myScope.displayExpress] = display;
            selectedRow[myScope.valueProp] = value;
            myScope.$selectedRow = selectedRow;
        }

        RadioDropdown = (function (superClass) {
            extend(RadioDropdown, superClass);

            function RadioDropdown($scope, $attrs, $controller, $timeout, itemList) {
                this.$scope = $scope;
                this.$attrs = $attrs;
                this.$controller = $controller;
                this.$timeout = $timeout;
                this.itemList = !!itemList ? itemList : [];
                RadioDropdown.__super__.constructor.call(this, this.$scope, this.$attrs, this.$controller, this.$timeout, this.itemList);
            };

            RadioDropdown.prototype.selectItem = function(item) {
                var self =this;
                if (self.onBeforeSelect(item) === false) {
                    return;
                }

                var selected = item.getSelect(),
                    me = this,
                    myScope = me.$scope;

                for(var i=0;i<this.itemList.length;i++){
                    var each = this.itemList[i];
                    each.unSelect();
                }
                if(selected){
                    myScope.setModelValue('');
                    myScope.display='';
                    myScope.$selectedRow = {};
                }else{
                    item.select();
                    myScope.setModelValue(item.attrs.value);
                    myScope.display=item.element.text();
                    myScope.$selectedRow = item.itemObj;

                }
                myScope.isShow=false;
                myScope.needFocus = true;
                myScope.inputText[0].focus();

                self.onSelect(item);
                me.apply();
            };

            RadioDropdown.prototype.refreshSelect = function(newValue) {
                var me = this,
                    scope = me.$scope,
                    text = '';
                if(scope.filter){
                    me.filterSource(newValue);
                }

                if(newValue != undefined){
                    var display = _.chain(me.itemList).filter(function(item){
                        item.unSelect();
                        return item.element.text() == newValue;
                    }).map(function(item){
                        item.select();
                        scope.$selectedRow = item.itemObj;
                        return item.attrs.value;
                    }).value();
                    text = display.join(me.valueSeparator);
                    if(text || scope.unmatchRemove){
                        scope.setModelValue(text);
                    }else{
                        scope.setModelValue(newValue);
                    }

                }else{
                    scope.setModelValue('');
                }
            };

            RadioDropdown.prototype.showSelect = function(value) {
                var me = this,
                    text = '';
                if(value != undefined){
                    var display = _.chain(me.itemList).filter(function(item){
                        item.unSelect();
                        return item.attrs.value == value;
                    }).map(function(item){
                        item.select();
                        me.$scope.$selectedRow = item.itemObj;
                        return item.element.text();
                    }).value();
                    text = display.join(me.valueSeparator);
                    if(text || me.$scope.unmatchRemove){
                        me.$scope.display =text;
                    }else{
                        if(!me.$scope.unmatchHide){
                            me.$scope.display =value;
                        }
                    }
                }else{
                    me.$scope.$selectedRow ={};
                    me.$scope.display = '';
                }
            };
            return RadioDropdown;
        })(BaseDropdown);

        /*复选框列表 */
        CheckBoxDropdown = (function(superClass) {
            extend(CheckBoxDropdown, superClass);

            function CheckBoxDropdown($scope, $attrs, $controller, $timeout, itemList) {
                var self;
                this.$scope = $scope;
                this.$attrs = $attrs;
                this.$timeout = $timeout;
                this.itemList = !!itemList ? itemList : [];
                CheckBoxDropdown.__super__.constructor.call(this, this.$scope, this.$attrs, this.$controller, this.$timeout, this.itemList);
                self = this;
                //对scope.$source分组、排序
                if($scope.groupExpress){
                    if($scope.source && !angular.isArray($scope.source)){
                        $scope.scope = myController.transObjToArr($scope.source);
                    }
                    createGroupSource(this.$scope);
                }
            };

            function createGroupSource(scope){
                var  groupFlag = "";
                sortGroupSource(scope);
                //设置分组首行标识
                for(var item in scope.source){
                    if(groupFlag!=scope.source[item][scope.groupExpress]){
                        scope.source[item].groupBorder=true;
                        groupFlag=scope.source[item][scope.groupExpress];
                    }
                }
            }
            //对scope.$scoure分组
            function sortGroupSource(scope){
                var groupProp,list,len,
                    source=scope.source,
                    groupMap={},
                    sourceTemp=[],
                    groupExpress = scope.groupExpress;
                len=source.length;
                for(var i=0;i<len;i++){
                    groupProp = source[i][groupExpress];
                    if(groupMap[groupProp] === undefined){
                        list = [];
                        list.push(source[i]);
                        groupMap[groupProp] = list;
                    }else{
                        groupMap[groupProp].push(source[i]);
                    }
                }
                for(var item in groupMap){
                    sourceTemp = sourceTemp.concat(groupMap[item]);
                }
                scope.source = sourceTemp;
            }


            CheckBoxDropdown.prototype.selectItem = function(item) {
                var self =this;
                if (self.onBeforeSelect(item) === false) {
                    return;
                }

                var displayArray = [],
                    submitArray = [],
                    me = this,
                    myScope = this.$scope,
                    length = this.itemList.length,
                    i = 0;
                if(item.getSelect()){
                    item.unSelect();
                    if(self.dropItemSelectAll){
                        self.dropItemSelectAll.unSelect();
                    }
                }else{
                    item.select();
                }
                myScope.$selectedRow = [];
                for(i=0;i<length;i++){
                    var each = me.itemList[i];
                    if(each.getSelect()){
                        displayArray.push(each.element.text());
                        submitArray.push(each.attrs.value);
                        myScope.$selectedRow.push(each.itemObj);
                    }
                }
                myScope.setModelValue(submitArray.join(me.valueSeparator));
                myScope.display=displayArray.join(me.valueSeparator);
                myScope.needFocus = true;
                myScope.inputText[0].focus();

                self.onSelect(item);
                if(myScope.timer){
                     $timeout.cancel(myScope.timer);
                }
                me.apply();
            };

            CheckBoxDropdown.prototype.showSelect = function(value) {
                var me =this,
                    myScope = me.$scope,
                    valArray,
                    display,
                    result;
                myScope.$selectedRow = [];
                if(value != undefined){
                    valArray = value.split(me.valueSeparator);
                    display = _.chain(me.itemList).filter(function(item){
                        item.unSelect();
                    result = _(valArray).filter(function(val){
                            return val == item.attrs.value;
                        });
                        return result.length>0;
                    }).map(function(item){
                        item.select();
                        myScope.$selectedRow.push(item.itemObj);
                        return item.element.text();
                    }).value();
                    text = display.join(me.valueSeparator);
                    if(text || me.$scope.unmatchRemove){
                        myScope.display = text;
                    }else{
                        if(!me.$scope.unmatchHide){
                            me.$scope.display =value;
                        }
                    }
                }else{
                    angular.forEach(me.itemList,function(item){
                        item.unSelect();
                    });
                    myScope.display = '';
                }
            };

            CheckBoxDropdown.prototype.displayInit = function(display,value){
                var myScope = this.scope,
                    displayArr = display.split(myScope.valueSeparator),
                    valueArr = value.split(myScope.valueSeparator),
                    i,
                    length=displayArr.length;
                for(i=0;i<length;i++){
                    if(!myScope.$selectedRow[i]){
                        myScope.$selectedRow[i] = {};
                    }
                    myScope.$selectedRow[i][myScope.displayExpress] = displayArr[i];
                    myScope.$selectedRow[i][myScope.valueProp] = valueArr[i];
                }
                //myScope.selectedRow = myScope.$selectedRow;

            };

            CheckBoxDropdown.prototype.refreshSelect = function(newValue) {
                var me = this,
                    text ;

                    var newValueArray = newValue.split(me.valueSeparator);
                    me.$scope.$selectedRow = [];
                    var display = _.chain(me.itemList).filter(function(item){
                        item.unSelect();
                        return _(newValueArray).filter(function(val){
                            return val==item.element.text();
                        }).length>0;
                    }).map(function(item){
                        item.select();
                        me.$scope.$selectedRow.push(item.itemObj);
                        return item.attrs.value;
                    }).value();
                    text = display.join(me.valueSeparator);
                    if(text || me.$scope.unmatchRemove){
                        me.$scope.setModelValue(text);
                    }else{
                        me.$scope.setModelValue(newValue);
                    }

            };

            CheckBoxDropdown.prototype.selectAll = function(){
                var me = this,
                    valueArr = [];

                if(me.$scope.timer){
                    $timeout.cancel(me.$scope.timer);
                }

                if(me.dropItemSelectAll.getSelect()){
                    me.dropItemSelectAll.unSelect();
                    me.$scope.setModelValue('');
                    me.showSelect('');
                }else{
                    me.dropItemSelectAll.select();
                    angular.forEach(me.itemList,function(item){
                        valueArr.push(item.attrs.value);
                    });
                    me.showSelect(valueArr.join(me.valueSeparator));
                    me.$scope.setModelValue(valueArr.join(me.valueSeparator));
                }
                me.$scope.needFocus = true;
                me.$scope.inputText[0].focus();
                me.apply();
            };

            return CheckBoxDropdown;

        })(BaseDropdown);

        DropdownFactory = {
            create:function ( $scope, $attrs, $controller, $timeout){

            var simpleList ;
            switch ($scope.listType) {
                case "single":
                    simpleList = new RadioDropdown($scope, $attrs, $controller, $timeout);
                    break;
                case "multi":
                    simpleList = new CheckBoxDropdown($scope, $attrs, $controller, $timeout);
                    break;
                default:
                    simpleList = new BaseDropdown($scope, $attrs, $controller, $timeout);
                    break;
            }
            return simpleList;
            }
        };

        return {
            scope:{
                source: '=',
                valueProp: '@',
                displayExpress: '@',
                valueSeparator:'@',
                groupExpress:'@',
                addEvent:'&',
                listType:'@',
                placeholder:'@',
                disabled:'=',
                readonly:'=',
                defaultOption:'=',
                selectedRow:'=',
                ngModelInit:'=ngModel',
                onSelect:'&',
                onBeforeSelect:'&'
            },
            replace:true,
            transclude: true,
            require:['^?ngModel','?gDropdown'],
            template:'<div ng-cloak class="form-dorpdown" verify-target><input type="text" verify-target class="form-text" ng-readonly="unfilter || readonly" ng-disabled ="disabled" ng-model="display" value="请选择" >'+
            '<a type="button" ng-click="showDropDown()" class="btn dropdown-toggle"> <i class="fi fi-caret"></i></a>'+
            '<ul ng-show="isShow" class="dropdown-menu form-dorpdown-menu" >'+
            '<g-dropitem ng-repeat="element in $source"  item="{{element}}" value="{{valueGetter(element)}}" text="{{displayGetter(element)}}" ></g-dropitem>' +
            '<li ng-show="addShow" class="form-dorpdown-additem" ng-click="addEvent()"><button class="btn"><i class="fi fi-add-circle"></i></button></li></ul>'+
            '</div>',
            restrict: 'E',
            controller:function($scope, $element, $attrs){
                $tabindex.register($element.find("input"),$element);
                return DropdownFactory.create( $scope, $attrs, this, $timeout);
            },
            compile:function(tElement, tAttrs,transclude){
                tElement.find("input").attr('ng-change', 'refreshSelect()');
                return function (scope, element,attrs,controllers) {
                    /*初始化参数*/
                    var ngModel = controllers[0],
                        myController = controllers[1],
                        keyIndex = -1,
                        inputText = element.find("input"),
                        ulElement = element.find("ul");
                    scope.inputText = inputText;
                    scope.isShow =false;
                    scope.scrollY = false;
                    scope.handInput = false;//子指令是否为页面上手输
                    scope.unmatchRemove = attrs.unmatchRemove=="true" || false;//不匹配的是否自动删除
                    scope.unmatchHide = attrs.unmatchHide == "true" || false;
                    scope.unfilter = attrs.unfilter=="true" || false;
                    scope.filter = attrs.unfilter == "false" || false;
                    scope.showEvent = attrs.showEvent == "click"?"click":"focus";
                    scope.groupExpress = attrs.groupExpress ||"";
                    scope.displayName = '';
                    scope.$selectedRow = scope.selectedRow || (scope.listType=="multi"?[]:{});
                    scope.displayExpress = attrs.displayExpress ?attrs.displayExpress:"key";
                    scope.valueProp = attrs.valueProp ?attrs.valueProp:"value";
                    scope.refreshSelect = function(){
                        var newVal = inputText.val();
                        myController.refreshSelect(newVal);
                    };

                    if(attrs.disabled=='disabled'){
                        scope.disabled = true;
                    }
                    if(attrs.readonly == 'readonly'){
                        scope.readonly = true;
                    }

                    angular.element(window).on("mousewheel",function(){
                        scope.isShow = false;
                        myController.apply();
                    });

                    ulElement = GillionLocationService.createHtmltoTop(ulElement);
                    scope.ulElement = ulElement;
                    ulElement.data(DROPITEMOBJ,myController);
                    ulElement.on("scroll",function(){
                        if(scope.timer){
                            $timeout.cancel(scope.timer);
                        }
                        scope.isShow = true;
                    });

                    //下拉框显示隐藏
                    scope.showDropDown = function(){
                        if(scope.disabled || scope.readonly){
                            return;
                        }
                        scope.isShow = !scope.isShow;
                        if(scope.isShow){
                            //下拉框定位
                            var location = GillionLocationService.calculateLocation(inputText);
                            ulElement.removeClass("ng-hide");
                            var ulWidth = ulElement[0].offsetWidth,
                                ulHeight = ulElement[0].offsetHeight;
                            if(ulElement.css("display") == "none"){
                                ulElement.css("display","block");
                                ulWidth = ulElement[0].offsetWidth;
                                ulHeight = ulElement[0].offsetHeight;
                                ulElement.css("display","none");
                            }
                            ulElement.css("left",location.left);
                            if(location.bottom > ulHeight){
                                ulElement.css("top",location.top+inputText[0].offsetHeight);
                            }else{
                                ulElement.css("top",location.top-ulHeight-1);
                            }
                            ulElement.css("display","block");
                            ulElement.css("min-width",inputText.closest('div').width());
                            scope.needFocus = true;
                            inputText[0].focus();
                        }else{

                        }
                    };

                    if(scope.source && !angular.isArray(scope.source)){
                        scope.$source = myController.transObjToArr(scope.source);
                    }else{
                        scope.$source = scope.source;
                    }
                    scope.sourceTemp = angular.copy(scope.$source);
                    var returnParamFn = function (arg) {
                        return arg;
                    };
                    var valueGetter = !!scope.valueProp ? $parse(scope.valueProp) : returnParamFn;
                    scope.displayGetter = !!scope.displayExpress ? $parse(scope.displayExpress) : returnParamFn;
                    scope.valueGetter = valueGetter;

                    //宽度
                    if (angular.isDefined(attrs.width)) {
                        element.css("width", attrs.width);
                    }
                    if (angular.isDefined(attrs.cssClass)) {
                        element.addClass(attrs.cssClass);
                    }
                    scope.setModelValue = function(val){
                        if(ngModel) {
                            ngModel.$setViewValue(val);
                        }
                    };
                    scope.getModelValue = function(){
                        if(ngModel) {
                            return ngModel.$modelValue;
                        }
                    };
                    if(ngModel){
                        ngModel.$formatters.push(function(value){
                            scope.setModelValue(value);
                            if(scope.unmatchHide && (scope.itemList || scope.itemList.length == 0)){
                                scope.display = '';
                            }
                            myController.showSelect(value);
                            if(inputText.val()!='' && angular.isDefined(attrs.onSelect)){
                                scope.onSelect({
                                    list: myController,
                                    item: scope.$selectedRow
                                });
                            }
                            return value;
                        });
                    }

                    if(attrs.addEvent) {
                        scope.addShow = true;
                    }

                    if(scope.placeholder){
                        inputText.attr("placeholder",scope.placeholder);
                    }

                    //默认选项
                    if(attrs.defaultOption){
                        if(attrs.defaultOption.indexOf("{")!=-1){
                            scope.defaultOption = JSON.parse(attrs.defaultOption);
                        }
                        myController.addDefaultOption();
                    }
                    //手动添加的子指令
                    transclude(scope, function (clone) {
                        angular.forEach(clone,function(each){
                            if(each.tagName=='LI' && !(angular.element(each).hasClass("checkbox-all"))){
                                scope.handInput = true;
                            }
                        });
                        ulElement.prepend(clone);
                    });

                    inputText.on('blur', function () {
                        if(!scope.isShow){
                            if(ngModel){
                                myController.showSelect(ngModel.$modelValue);
                                myController.apply();
                            }
                        }else{
                            scope.timer = $timeout(function () {
                                if(ngModel){
                                    myController.showSelect(ngModel.$modelValue);
                                }
                                scope.isShow =false;
                                myController.apply();
                            }, 200);
                        }
                    });

                    var clickFun = function (event) {
                        if(scope.timer){
                            $timeout.cancel(scope.timer);
                        }
                        var target = event.srcElement || event.target;
                        if(scope.isShow) {
                            if (element.find(target).length === 0 && ulElement.find(target).length === 0
                                && target != ulElement[0]) {

                                scope.isShow = false;
                                if(ngModel){
                                    myController.showSelect(ngModel.$modelValue);
                                }
                                myController.apply();
                                scope.needFocus = false;
                            }
                        }
                    };

                    //点击隐藏
                    $document.on('mousedown', clickFun);
                    if(window.parent != window){
                        angular.element(window.parent).on('click', clickFun);
                    }

                    //刷新时清空 （非手动输入子指令）
                    if(!scope.handInput){
                        scope.$watchCollection("source",function(){
                            if(!angular.isArray(scope.source)){
                                scope.$source = myController.transObjToArr(scope.source);
                            }else{
                                scope.$source = scope.source;
                            }
                            if(attrs.defaultOption){
                                if(attrs.defaultOption.indexOf("{")!=-1){
                                    scope.defaultOption = JSON.parse(attrs.defaultOption);
                                }
                                myController.addDefaultOption();
                            }
                            scope.sourceTemp = angular.copy(scope.$source);
                        });

                    }

                    if(attrs.disabled){
                        scope.$watch("disabled",function(newVal){
                            if(newVal){
                                element.attr("disabled");
                            }else{
                                element.removeAttr("disabled");
                            }
                        })
                    }

                    if(attrs.readonly){
                        scope.$watch("readonly",function(newVal){
                            if(newVal){
                                element.attr("readonly","readonly");
                            }else{
                                element.removeAttr("readonly");
                            }
                        })
                    }

                    // 监控selectedRow变化
                    if(attrs.selectedRow){
                        scope.$watch("$selectedRow",function(newVal){
                            myController.onBeforeSelect();
                            scope.selectedRow = newVal;
                        })
                    }

                    scope.$on("$destroy",function(){
                        ulElement.remove();
                    })

                    //定位
                    inputText.on(scope.showEvent,function(e){
                        if(GillionMsgService.isUnderMasked(inputText[0])){
                            return ;
                        }

                        if(scope.needFocus){
                            //点击后要聚焦 但不做任何事
                            scope.needFocus = false;
                            return;
                        }
                        var location = GillionLocationService.calculateLocation(inputText);
                        ulElement.removeClass("ng-hide");
                        var ulWidth = ulElement[0].offsetWidth,
                            ulHeight = ulElement[0].offsetHeight;
                        if(ulElement.css("display") == "none"){
                            ulElement.css("display","block");
                            ulWidth = ulElement[0].offsetWidth;
                            ulHeight = ulElement[0].offsetHeight;
                            ulElement.css("display","none");
                        }
                        ulElement.css("left",location.left);
                        if(location.bottom > ulHeight){
                            ulElement.css("top",location.top+inputText[0].offsetHeight);
                        }else{
                            ulElement.css("top",location.top-ulHeight-1);
                        }
                        ulElement.css("min-width",inputText.closest('div').width());
                        ulElement.css("display","block");
                        scope.isShow = true;
                        scope.refreshSelect();
                        myController.apply();
                    });
                    inputText.on("keydown",function(e){
                        var currKey = e.keyCode || e.which || e.charCode,
                            keyLength = ulElement.find("li[ng-show!='addShow']").length;
                        if(currKey==13){
                            if(scope.isShow){
                                if(myController.dropItemSelectAll && keyIndex == keyLength-1){
                                    myController.selectAll();
                                }else{
                                    var item = myController.itemList[keyIndex];
                                    if(item){
                                        item.removeSelectStyle();
                                        item.element[0].click();
                                        if(scope.listType != "multi"){
                                            keyIndex = -1;
                                        }
                                        scope.isShow = false;
                                        myController.apply();
                                    }
                                }
                            }
                            e.stopPropagation();
                            e.preventDefault();
                        }else if(currKey == 38 || currKey == 40 || currKey == 32){
                            e.stopPropagation();
                            e.preventDefault();
                        }
                    })

                    //输入框键盘输入事件
                    inputText.on("keyup", function (e) {
                        var currKey = e.keyCode || e.which || e.charCode,
                            //keyLength = myController.itemList.length,
                            keyLength = ulElement.find("li[ng-show!='addShow']").length;
                        switch (currKey) {
                            //方向上键
                            case 38:
                                var keyNextIndex = keyIndex<0?keyIndex+keyLength:keyIndex;
                                keyIndex = keyIndex<0?keyIndex+keyLength:(keyIndex-1+keyLength)%keyLength;
                                if(myController.dropItemSelectAll ){
                                    if(keyIndex == keyLength-1){
                                        myController.dropItemSelectAll.addSelectStyle();
                                        myController.itemList[keyNextIndex].removeSelectStyle();
                                    }else{
                                        myController.dropItemSelectAll.removeSelectStyle();
                                        myController.itemList[keyIndex].addSelectStyle();
                                        if(keyNextIndex < keyLength-1 )
                                        myController.itemList[keyNextIndex].removeSelectStyle();
                                    }
                                }else{
                                    myController.itemList[keyIndex].addSelectStyle();
                                    myController.itemList[keyNextIndex].removeSelectStyle();
                                }

                                if(keyIndex > 4){
                                    ulElement[0].scrollTop = (keyIndex-4)*25;
                                }else{
                                    ulElement[0].scrollTop = 0;
                                }
                                e.stopPropagation();
                                e.preventDefault();
                                break;
                            //方向下键
                            case 40:
                                var keyLastIndex = keyIndex<0?keyIndex+keyLength:keyIndex;
                                keyIndex = (keyIndex+1)%keyLength;
                                if(myController.dropItemSelectAll ){
                                    if(keyIndex == keyLength-1){
                                        myController.dropItemSelectAll.addSelectStyle();
                                        myController.itemList[keyLastIndex].removeSelectStyle();
                                    }else{
                                        myController.dropItemSelectAll.removeSelectStyle();
                                        myController.itemList[keyIndex].addSelectStyle();
                                        if(keyLastIndex < keyLength-1 )
                                        myController.itemList[keyLastIndex].removeSelectStyle();
                                    }
                                }else{
                                    myController.itemList[keyIndex].addSelectStyle();
                                    myController.itemList[keyLastIndex].removeSelectStyle();
                                }
                                if(keyIndex > 4){
                                    ulElement[0].scrollTop = (keyIndex-4)*25;
                                }else{
                                    ulElement[0].scrollTop = 0;
                                }
                                e.stopPropagation();
                                e.preventDefault();
                                break;
                            //空格键
                            case 32:
                                if(myController.dropItemSelectAll && keyIndex == keyLength-1){
                                    myController.selectAll();
                                }else{
                                    var item = myController.itemList[keyIndex];
                                    if(item){
                                        item.removeSelectStyle();
                                        if(scope.listType != "multi"){
                                            keyIndex = -1;
                                        }
                                        item.element[0].click();
                                    }
                                }
                                return false;
                                break;
                            //回车键
                            case 13:
                                break;
                            default:
                                break;
                        }
                    });
                }
            }
        }
    }
});